<?php

namespace app\admin\controller;

use app\admin\service\UserLevelService;
use support\spark\model\user\UserLevel;
use support\Request;
use support\View;

class UserLevelController extends Curd
{
    /**
     * 获取列表
     */
    public function index()
    {
        if (request()->isAjax()) {
            $userLevelService = new UserLevelService();
            $res = $userLevelService->getList(request()->all());
            return sparkSuccess($res);
        }
        return view('user_level/index');
    }

    /**
     * 添加
     */
    public function add()
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();

            $userLevelService = new UserLevelService();
            $res = $userLevelService->addUserLevel($param);
            return sparkSuccess($res);
        }

        return view('user_level/add');
    }

    /**
     * 编辑
     */
    public function edit()
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();
            $userLevelService = new UserLevelService();
            $res = $userLevelService->editUserLevel($param);
            return sparkSuccess($res);
        }

        $id = request()->input('id');
        $userLevelModel = new UserLevel();
        View::assign([
            'info' => $userLevelModel->getInfoById($id)
        ]);
        return view('user_level/edit');
    }

    /**
     * 删除
     */
    public function del()
    {
        $id = request()->input('id');
        $userLevelModel = new UserLevel();
        $userLevelModel->delById($id);
        return sparkSuccess(dataReturn(0, '删除成功'));
    }

}